import {reactive, toRefs} from 'vue'
import axios from 'axios'
interface IRresult<T> {
  result: null|T;
  loading: boolean;
  error: any
}
const useURLLoader = <T = any>(url: string) => {//T传递到函数中，data希望获取T，传入
  const data:IRresult<T> = reactive({
    result: null,
    loading: true,
    error: null
  })
  axios.get(url).then(rawData => {
    data.result = rawData.data
  }).catch(e => {
    data.error = e
  }).finally(()=>{
    data.loading = false
  })
  return toRefs(data)
}